package com.jdk8.demo.functional.supplier;

import java.util.Comparator;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;

/**
 * 供给型接口
 * 参数：T
 * 方法：get()
 */
public class SupplierTest {
    public static void main(String[] args) {
        Supplier<String> supplier = () -> "hello";
        System.out.println(supplier.get());
        System.out.println("---------------------");
        Integer sum = operation(1, 2, (a, b) -> a + b);
        System.out.println(sum);

        System.out.println("---------------------");

        String s = comparator("abc", "ab", (a, b) -> a.indexOf('a') >= 0 ? 0 : -1 - b.indexOf('a') >= 0 ? 0 : -1);
        System.out.println(s);

    }

    public static <T> T operation(T a, T b , BinaryOperator<T> binaryOperator){
        return binaryOperator.apply(a, b);
    }


    public static String comparator(String a, String b, Comparator<String> comparator){
        return BinaryOperator.minBy(comparator).apply(a, b);
    }

}